let a = "1010", b = "1011"
var addBinary = function (a, b) {
    let k = 0
    let arr = []
    let i = a.length - 1
    let j = b.length - 1
    while (i >= 0 || j >= 0 || k) {
        const n1 = i >= 0 ? +a[i--] : 0
        const n2 = j >= 0 ? +b[j--] : 0
        const sum = n1 + n2 + k
        arr.unshift(sum % 2)
        k = sum > 1 ? 1 : 0
    }
    return arr.join('')
};
console.log(addBinary(a, b));
